import json

import yaml


def parser_file(file_path: str):
    filepath = str(file_path)
    with open(filepath, "r", encoding="utf-8") as f:
        if ".yaml" in filepath:
            return yaml.safe_load(f)
        elif ".json" in filepath:
            return json.load(f)
        else:
            f.read()


def write_file(filepath, data: dict):

    with open(filepath, "w", encoding="utf-8") as f:
        if ".yaml" in filepath:
            yaml.safe_dump(data, f, allow_unicode=True)
        elif ".json" in filepath:
            json.dump(data, f, ensure_ascii=False)
        else:
            f.write(json.dumps(data))


if __name__ == '__main__':
    print(parser_file("..\\env\\test.yaml"))
